package com.jzo2o.customer.controller.worker;

import cn.hutool.core.bean.BeanUtil;
import com.jzo2o.common.utils.UserContext;
import com.jzo2o.customer.model.domain.BankAccount;
import com.jzo2o.customer.model.dto.request.BankAccountUpsertReqDTO;
import com.jzo2o.customer.model.dto.response.BankAccountResDTO;
import com.jzo2o.customer.service.IBankAccountService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController("bankAccountController")
@RequestMapping("/worker/bank-account")
@Api(tags = "服务端 - 银行账户接口")
public class BankAccountController {
    @Resource
    private IBankAccountService bankAccountSerive;


    /**
     * 新增或更新银行账户
     */
    @PostMapping
    public void bankAdd(@RequestBody BankAccountUpsertReqDTO bankAccountUpsertReqDTO) {
        BankAccount bankAccount = BeanUtil.toBean(bankAccountUpsertReqDTO, BankAccount.class);
        bankAccount.setId(UserContext.currentUserId());
        bankAccount.setType(2);
        bankAccountSerive.saveOrUpdate(bankAccount);
    }

    /**
     * 获取当前用户银行账号
     */
    @GetMapping("/currentUserBankAccount")
    public BankAccountResDTO currentUserBankAccount() {
        Long userId = UserContext.currentUserId();
        BankAccount bankAccount = bankAccountSerive.getById(userId);
        return BeanUtil.toBean(bankAccount, BankAccountResDTO.class);
    }
}
